package org.zuel.boot.demo.controller;

import org.zuel.boot.demo.entity.DemoFile;
import org.zuel.boot.demo.service.IDemoFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.zuel.boot.demo.web.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 文件 控制器
 *
 * @author ikun
 */
@Api(tags = "文件管理")
@RestController
@RequestMapping("/zuel")
public class DemoFileController{

    private IDemoFileService demoFileService;

    @Autowired
    public DemoFileController(IDemoFileService demoFileService){
        this.demoFileService = demoFileService;
    }

    @ApiOperation("查询列表文件")
    @GetMapping("/demoFile/list")
    public PageResult<DemoFile> list(HttpServletRequest request) {
        PageParam<DemoFile> pageParam = new PageParam<>(request);
        return demoFileService.list(pageParam);
    }

    @ApiOperation("查询单个文件")
    @GetMapping("/demoFile/get/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return demoFileService.read(id);
    }

    @ApiOperation("添加文件")
    @PostMapping("/demoFile/add")
    public JsonResult add(@RequestBody DemoFile model) {
    return demoFileService.add(model);
    }

    @ApiOperation("修改文件")
    @PostMapping("/demoFile/update")
    public JsonResult update(@RequestBody DemoFile model) {
    return demoFileService.update(model);
    }

    @ApiOperation("删除文件")
    @GetMapping("/demoFile/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return demoFileService.delete(ids);
    }

}